function xianshi(t) {
	t.getElementsByTagName("dl")[0].className = "xianshi";
}

function yincang(t) {
	t.getElementsByTagName("dl")[0].className = "yincang";
}
window.onload = function() {
	//新new一个轮播对象 
	var swiper = new Swiper('.swiper-container', {
		pagination: '.swiper-pagination',
		nextButton: '.swiper-button-next',
		prevButton: '.swiper-button-prev',
		slidesPerView: 1,
		paginationClickable: true,
		spaceBetween: 30,
		loop: true
	});
	k_bkcp(bktj, 8);
	//	k_cp(left_shangpin, 10);
	allshop();
}

function k_bkcp(t, length) {
	var k_bktj = document.getElementsByClassName("k_bktuijian")[0];
	var ul = k_bktj.getElementsByTagName("ul")[0];
	for(var i = 0; i < length; i++) {
		var li = document.createElement("li");
		ul.appendChild(li);
		if(length <= 8) {
			if(i == 3 || i == 7) {
				li.className = "mr0";
			} else {
				li.className = "mr16";
			}
		} else {
			if(i == 1 || i == 5 || i == 9) {
				li.className = "mr0";
			} else {
				li.className = "mr16";
			}
		}
		var a = document.createElement("a");
		li.appendChild(a);
		a.href = "#";
		var cpimg = document.createElement("img");
		a.appendChild(cpimg);
		cpimg.className = "imgcla0";
		cpimg.src = t[i].src;
		cpimg.title = t[i].name;
		var p1 = document.createElement("p");
		a.appendChild(p1);
		p1.className = "k_jg_qian";
		p1.innerHTML = '<label class="f12">￥</label><span class="k_jiage f20">' + t[i].jiage + '</span><label class="f13 fr">人购买</label><span class="k_gmrs f13 fr">' + t[i].gmrs + '</span>'
		var p2 = document.createElement("p");
		a.appendChild(p2);
		p2.className = "k_cpname";
		p2.innerHTML = t[i].name;
		p2.title = t[i].name;
		var div = document.createElement("div");
		div.className = "k_shunfeng";
		a.appendChild(div);
		div.innerHTML = '<img src="img/icon_04.png" />';
	}
}

function allshop() {
	var shopsarr; //所有商品的数组
	var category; //商品的分类的数组

	$.ajax({
		type: "post",
		url: "http://hw.mashupcloud.cn/mcloud/SQL/SELECT FeiLei/?entity=Category&name=SELECT FeiLei&token=" + token,
		async: true,
		success: function(data) {
			category = JSON.parse(data)[2];
			//console.log(category); //所有商品的信息，列表字符串
			$.ajax({
				type: "post",
				url: "http://hw.mashupcloud.cn/mcloud/SQL/SELECT ALL/?entity=Shops&name=SELECT&token=" + token,
				async: true,
				success: function(data) {
					shopsarr = JSON.parse(data)[2];//所有商品的信息数组
					var bg = document.getElementsByClassName("bg")[0];
					var shangbu = bg.getElementsByClassName("k_sb")[0];
					for(var j = 0; j < category.length; j++) {
						var k_bktj = document.createElement("div");
						k_bktj.className = "k_bktuijian";
						shangbu.appendChild(k_bktj);
						var k_1 = document.createElement("div");
						k_bktj.appendChild(k_1);
						k_1.className = "k_1";
						k_1.innerHTML = '<div><a name="div' + (j + 1) + '">' + category[j].name + '</a></div><li class="hw mr16"><a href="#"><img class="mt10" src="img/c' + (j + 1) + '.jpg" /></a></li><ul></ul>';
						var ul = k_bktj.getElementsByTagName("ul")[0];
						for(var i = 0; i < shopsarr.length; i++) {
							if(category[j].name == shopsarr[i].category) {
								var li = document.createElement("li");
								ul.appendChild(li);
								if(length <= 8) {
									if(i % 4 == 0) {
										li.className = "mr0";
									} else {
										li.className = "mr16";
									}
								} else {
									if(i == 1 || i == 5 || i == 9) {
										li.className = "mr0";
									} else {
										li.className = "mr16";
									}
								}
								var a = document.createElement("a");
								li.appendChild(a);
								a.href = "#";
								var cpimg = document.createElement("img");
								a.appendChild(cpimg);
								if(i == 9) {
									cpimg.src = "img/cjs" + (j + 1) + ".jpg";
									cpimg.className = "imgcla2";
								} else {
									cpimg.src = shopsarr[i].src;
									cpimg.className = "imgcla1";
									cpimg.title = shopsarr[i].name;
									var p1 = document.createElement("p");
									li.appendChild(p1);
									p1.className = "k_jg_qian pl10 pr10";
									p1.innerHTML = '<label class="f12">￥</label><span class="k_jiage f20">' + shopsarr[i].price + '</span><label class="f13 fr"></label><span class="k_gmrs f13 fr">' + shopsarr[i].PLnum + '</span>'
									var p2 = document.createElement("p");
									li.appendChild(p2);
									p2.className = "f12 pl10 pr10 mt10 slh";
									p2.innerHTML = shopsarr[i].name;
									p2.title = shopsarr[i].name;
									var div = document.createElement("div");
									div.className = "k_shunfeng";
									li.appendChild(div);
									div.innerHTML = '<img src="img/icon_04.png" />';
								}
							}
						}
					}
				}
			});
		}
	});

}

function k_cp(t, length) {
	var arr = ["生日礼物", "本周新品", "送女友礼物", "送男友礼物", "成双成对礼物"];
	var bg = document.getElementsByClassName("bg")[0];
	var shangbu = bg.getElementsByClassName("k_sb")[0];
	for(var j = 0; j < 5; j++) {
		var k_bktj = document.createElement("div");
		k_bktj.className = "k_bktuijian";
		shangbu.appendChild(k_bktj);
		var k_1 = document.createElement("div");
		k_bktj.appendChild(k_1);
		k_1.className = "k_1";
		k_1.innerHTML = '<div><a name="div' + (j + 1) + '">' + arr[j] + '</a></div><li class="hw mr16"><a href="#"><img class="mt10" src="img/c' + (j + 1) + '.jpg" /></a></li><ul></ul>';
		var ul = k_bktj.getElementsByTagName("ul")[0];
		for(var i = 0; i < length; i++) {
			var li = document.createElement("li");
			ul.appendChild(li);
			if(length <= 8) {
				if(i % 4 == 0) {
					li.className = "mr0";
				} else {
					li.className = "mr16";
				}
			} else {
				if(i == 1 || i == 5 || i == 9) {
					li.className = "mr0";
				} else {
					li.className = "mr16";
				}
			}
			var a = document.createElement("a");
			li.appendChild(a);
			a.href = "#";
			var cpimg = document.createElement("img");
			a.appendChild(cpimg);
			if(i == 9) {
				cpimg.src = "img/cjs" + (j + 1) + ".jpg";
				cpimg.className = "imgcla2";
			} else {
				cpimg.src = t[i + j * 8].src;
				cpimg.className = "imgcla1";
				cpimg.title = t[i].name;
				var p1 = document.createElement("p");
				li.appendChild(p1);
				p1.className = "k_jg_qian pl10 pr10";
				p1.innerHTML = '<label class="f12">￥</label><span class="k_jiage f20">' + t[i].jiage + '</span><label class="f13 fr"></label><span class="k_gmrs f13 fr">' + t[i].plNum + '</span>'
				var p2 = document.createElement("p");
				li.appendChild(p2);
				p2.className = "f12 pl10 pr10 mt10 slh";
				p2.innerHTML = t[i].name;
				p2.title = t[i].name;
				var div = document.createElement("div");
				div.className = "k_shunfeng";
				li.appendChild(div);
				div.innerHTML = '<img src="img/icon_04.png" />';
			}

		}
	}
}
window.onscroll = function() {
	if(document.getElementById("k_center_tettle")) {
		var ct = document.getElementById("k_center_tettle");
	} else {
		var ct = document.getElementById("guding");
	}
	//var juli_top = document.getElementById("k_center_tettle").offsetTop;//获取距离父节点的距离
	//var sTop =document.body.scrollTop//只支持谷歌
	var sTop = $(document).scrollTop();
	if(sTop >= 1600) {
		if(sTop < 2700) {
			ct.id = "guding";
			var lis = ct.getElementsByTagName("li");
			for(var i = 0; i < lis.length; i++) {
				lis[i].className = "";
			}
			lis[0].className = "bgcol";
		} else if(sTop > 2700 && sTop <= 3850) {
			ct.id = "guding";
			var lis = ct.getElementsByTagName("li");
			for(var i = 0; i < lis.length; i++) {
				lis[i].className = "";
			}
			lis[1].className = "bgcol";
		} else if(sTop > 3850 && sTop <= 4980) {
			ct.id = "guding";
			var lis = ct.getElementsByTagName("li");
			for(var i = 0; i < lis.length; i++) {
				lis[i].className = "";
			}
			lis[2].className = "bgcol";
		} else if(sTop > 4980 && stop <= 6080) {
			ct.id = "guding";
			var lis = ct.getElementsByTagName("li");
			for(var i = 0; i < lis.length; i++) {
				lis[i].className = "";
			}
			lis[3].className = "bgcol";
		} else if(sTop > 6080 && stop <= 7000) {
			ct.id = "guding";
			var lis = ct.getElementsByTagName("li");
			for(var i = 0; i < lis.length; i++) {
				lis[i].className = "";
			}
			lis[4].className = "bgcol";
		} else {
			ct.id = "guding";
			var lis = ct.getElementsByTagName("li");
			for(var i = 0; i < lis.length; i++) {
				lis[i].className = "";
			}
			lis[0].className = "bgcol";
		}
	} else if(sTop < 1600) {
		ct.id = "k_center_tettle";
		var lis = ct.getElementsByTagName("li");
		for(var i = 0; i < lis.length; i++) {
			lis[i].className = "";
		}
		lis[0].className = "bgcol";
	}
}

function login() {
	document.getElementById("k_zong").style.display = "none";
	$("#y_zong").slideToggle("slow", function() {
		document.getElementById("y_zong").style.display = "block";
	});
}

function closelogin() {
	$("#y_zong").slideToggle("slow", function() {
		document.getElementById("y_zong").style.display = "none";
	});
}

function zhuce() {
	alert(1)
	document.getElementById("y_zong").style.display = "none";
	$("#k_zong").slideToggle("slow", function() {
		document.getElementById("k_zong").style.display = "block";
	});
}

function closezhuce() {
	$("#k_zong").slideToggle("slow", function() {
		document.getElementById("k_zong").style.display = "none";
	});
}
//
//function tiaozhuan(t) {
//	$("#k_zong").slideToggle("slow", function() {
//		//		var x = t.className;
//		//		location.href = "#div" + x;
//		//		var sTop = $(document).scrollTop();
//		if(t == 1) {
//			$(document).scrollTop(1600);
//			//			sTop = 1600;
//		} else if(t == 2) {
//			$(document).scrollTop(2700);
//			//			sTop = 2700;
//		} else if(t == 3) {
//			$(document).scrollTop(3850);
//
////			sTop = 3850;
//		} else if(t == 4) {
//			$(document).scrollTop(4980);
//
////			sTop = 4980;
//		} else if(t == 5) {
//			$(document).scrollTop(6080);
//
////			sTop = 6080;
//		}
//	});
//
//}

function inputborder(t) {
	t.className = "k_gongyong bor";
}

function leftinputborder() {
	t.className = "k_gongyong bor1";

}

//点击注册
function zhuce() {
	$.ajax({
		type: "post",
		url: "http://hw.mashupcloud.cn/mcloud/system/user_register.do",
		data: {
			token: token,
			username: $("#username").val(),
			password: md5($("#password").val())
		},
		success: function(data) {
			console.log(data);
		}
	});
}